package com.xiaoming.project.core.string;

import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;

public class StringJoinerTest {
    static void stringJoinerTest() {
        List<String> testList = new ArrayList<String>();
        testList.add("xiaoming");
        testList.add("xiaoming");
        testList.add("xiaoming");
        testList.add("xiaoming");
        testList.add("xiaoming");

        // String.join
        System.out.println(String.join(",", testList));

        // Collectors.join
        String result = testList.stream().collect(Collectors.joining(","));
        System.out.println(result);

        // StringJoiner
        StringJoiner stringJoiner = new StringJoiner(",");
        stringJoiner.add("xiaohong");
        stringJoiner.add("xiaohong");
        stringJoiner.add("xiaohong");
        stringJoiner.add("xiaohong");
        stringJoiner.add("xiaohong");
        System.out.println(stringJoiner.toString());
    }
}